<template>
    <div class="main">
        <div class="bindingalipay" style="margin-top: 12px;">
            <div class="bjcl_fff wh_100"  style="margin-bottom: 30px;">
                <Labelinput :placeholder="nameText" :labelcopy="'真实姓名'" :width="64" :cbfn="'nametirgget'" @nametirgget="bindingAlipayName" :isrealname="isrealname"></Labelinput>
                <Labelinput :placeholder="'请填写正确的支付宝账号'" :labelcopy="'支付宝'" :width="64" :cbfn="'idtirgget'" @idtirgget="bindingAlipayId"></Labelinput>
            </div>
            <Confimbtn :copy="'保 存'" :disablebtn="disablebtn" :cbfn="cbfn" @confimtrigger="bingdingSubmit"></Confimbtn>
        </div>
    </div>
    <!-- 组件的模板 -->
        
</template>

<script>
    /**
     *  引入工具类库 或 Native API
     *  example : import widget from 'gapi/widget'
     */

    import * as util from 'js/util.js'
    import widget from 'gapi/widget'
    import commonPage from 'clientApi/commonPage.js'
    import cache from 'gapi/cache.js'
    import safety from 'gapi/safety.js'
    import * as common from 'js/common.js'
    // import ApiClientUi from 'clientApi/ApiClientUi.js'
    /**
     *  引入组件 以及 组件接口(Action)
     *  example : import Somecomponents from 'components/Somecomponents/Somecomponents'
     */

    import Labelinput from 'components/Labelinput/Labelinput'
    import Confimbtn from 'components/Confimbtn/Confimbtn'

    /**
     *  组件实例对象
     */
    export default {
        components: {
            Labelinput,
            Confimbtn
        },
        data: function(){
            return{
                disablebtn:true,
                cbfn:'confimtrigger',
                alipayName:'',
                alipayId:'',
                valChange:'',
                bindType:'alipay',
                nameText: '务必与支付宝绑定姓名一致',
                isrealname: true,
            }
        },
        methods: {
            /**
             * 初始化
             * @method init
             * @public
             * @return {Null} void
             */
            init (){
                let real_name = util.getUrddataString('real_name')
                if(real_name != '' && real_name != undefined && real_name != 'null'){
                    this.alipayName = real_name
                    this.nameText = real_name
                    this.isrealname = true
                }else{
                    this.isrealname = false
                }
        
            },
            bingdingSubmit(){
                this.disablebtn = true;                
                commonPage.loadPageStatus('loading')                
                util.ajax({
                    url:'/wallet/bind',
                    type:'POST',
                    data:{
                        account: this.alipayId,
                        account_type: 1,
                        account_plus: '',
                        name: this.alipayName,
                    },
                    timeout:10000,
                    success:(data) => {
                        commonPage.loadPageStatus('loadSuccess')
                        this.disablebtn = false;
                        if(data.errno == 0){
                            widget.toast('绑定成功')
                            let encodeStr = encodeURIComponent(`last_pageUrl=1`)
                            location.href = `dmsaas://ApplyforWithdrawal?urdData=${encodeStr}`
                        }else{
                            widget.toast(data.errmsg)
                        }
                    },
                    error:function(status){
                        commonPage.loadPageStatus('loadSuccess')
                        this.disablebtn = false;
                        widget.toast('服务器异常')
                    }
                })
            },
            bindingAlipayName(val,target){
                let znVal = val.replace(/[^\u4E00-\u9FA5\·]/g,'')
                target.value = znVal;
                this.alipayName = znVal;
            },
            bindingAlipayId(val){
                this.alipayId = val;
            },
        },
        computed:{
            valChange:function(){
                return '' + this.alipayId + this.alipayName;
            }
        },
        watch:{
            valChange:function(){
                if(this.alipayName && this.alipayId){
                    this.disablebtn = false;
                }else{
                    this.disablebtn = true;
                }
            }
        },
        created(){
            this.init();
            commonPage.updateTitleBar({
                backAction: 'goBack',
                leftAction: 'goBack'
            })
            window.goBack = () => {
                // location.href = "dmsaas://WithdrawalWay"
                cache.getMemoryCache('yyWithdrayalwayWebViewID',function(data){
                    if(data){
                        commonPage.goBack(1, {}, data.webViewID)
                    }
                })
            }
            
        }
        
    }

    
</script>

<!-- CSS 样式 -->
<!-- <style src="static/css/global.css"></style> -->
<style src="../../static/css/base.css"></style>



